package com.igroupes.ovineherd.model.Style;

import com.igroupes.ovineherd.exception.ModelException;
import com.igroupes.ovineherd.model.enums.FormKey;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@EqualsAndHashCode(callSuper = true)
@Data
@ToString(callSuper = true)
public class FileStyle extends BasicStyle{

    /**
     * 必须的 true 是 false 否
     */
    protected Boolean required = false;
    private Integer maxLength; //个数
    private String accept; //允许格式
    private String receiver;
    private Integer maxSize = 5*1024*1024;

    public FileStyle(String label, Boolean required, Object value, Integer maxLength, String accept, String receiver) {
        super(label, value);
        this.type = FormKey.FILE.getCode();
        this.maxLength = maxLength;
        this.accept = accept;
        this.required = required;
        this.receiver = receiver;
    }

    @Override
    public Boolean verify(Object o) {
        if(!(o instanceof FileStyle)){
            throw new ModelException("校验style类类型错误， check");
        }
        FileStyle style = (FileStyle) o;
        super.verify(o);
//        if(!style.getReadonly()){
//            for (Object g :
//                    style.getGroup()) {
//                if(!(g instanceof Group)){
//                    throw new ModelException(style.getLabel()+"传值类型错误");
//                }
//                Group group1 = (Group) g;
//                group1.verify(group1);
//            }
//        }
        return true;
    }
}
